package cjy.javatest.observer;

public class Main {
    public static void main(String[] args) {
        // Create a subject
        Subject subject = new ConcreteSubject();

        // Create observers
        Observer observer1 = new ConcreteObserver("Observer 1");
        Observer observer2 = new ConcreteObserver("Observer 2");

        // Attach observers to the subject
        subject.attach(observer1);
        subject.attach(observer2);

        // 改变subject的状态，通知所有观察者
        subject.setState(10);

        // Detach an observer from the subject
        subject.detach(observer1);
        // Change the state again
        subject.setState(20);
    }
}
